<template>
    <div>
        <a-modal
         v-model:visible="visible" 
         :title="formState.id?formState.view?'查看':'编辑关键指标':'新增关键指标'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="enterprise-add-edit-modal"
         :width="700"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="add-edit-form">
                    <a-form-item label="项目名称">
                        <a-input
                        v-model:value="formState.fxmmc"
                        placeholder="请输入项目名称"
                        v-decorator="[
                            'fxmmc', { initialValue:formState.fxmmc, rules: rules.fxmmc}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="警戒限">
                        <a-input
                        v-model:value="formState.fjjx"
                        placeholder="请输入警戒限"
                        v-decorator="[
                            'fjjx', { initialValue:formState.fjjx, rules: rules.fjjx}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="行动限">
                        <a-input
                        v-model:value="formState.fhdx"
                        placeholder="请输入行动限"
                        v-decorator="[
                            'fhdx', { initialValue:formState.fhdx, rules: rules.fhdx}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="合格限">
                        <a-input
                        v-model:value="formState.fhgx"
                        placeholder="请输入合格限"
                        v-decorator="[
                            'fhgx', { initialValue:formState.fhgx, rules: rules.fhgx}
                        ]"/>
                    </a-form-item>
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <a-button v-if="!formState.view" style="margin: 0 20px;" class="blue-btn" type="primary" @click="handleOk(true)">保存</a-button>
                <a-button v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">保存并关闭</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import { queryYwzdByCode } from '../service/index'
import moment from 'moment'
export default {
    components:{
        compSelector,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fxmmc: [{
                    required: true,
                    message: '请输入项目名称',
                    trigger: 'blur',
                }],
                fjjx: [{
                    required: true,
                    message: '请输入警戒限',
                    trigger: 'blur',
                }],
                fhdx: [{
                    required: true,
                    message: '请输入行动限',
                    trigger: 'blur',
                }],
                fhgx: [{
                    required: true,
                    message: '请输入合格限',
                    trigger: 'blur',
                }],
            },
            rylxList:[],
        }
    },
    watch:{

    },
    mounted(){
        queryYwzdByCode().then(res=>{
            if(res.code == 200){
                this.rylxList = res.result
            }else{
                this.$message.warning(res.message)
            }
        })
    },
    methods:{
        getData(val){
            this.formState = {}
            this.formState = val
            //console.log('是否再次获取',val)
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    if(this.formState.id){
                        this.$emit('editItem',{...this.formState,...values},val)
                    }else{
                        this.$emit('addItem',{...this.formState,...values},val)
                    }
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.enterprise-add-edit-modal{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
        }
        .ant-form-item-label{
            width: 85px;
        }
        .ant-form-item-control-wrapper{
            width: 180px;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>